<?php
/*
Plugin Name: Sitewide Multi-Widget
Plugin URI: http://iblog.stjschool.org/
Description: "Three-in-One": Recent Sitewide Posts(category, tags, avatars). Sitewide Tag Cloud, and Daily, Weekly, Monthly, Yearly Sitewide Archives. Uses 'tags_blog_id' from Donncha's Sitewide Tags Pages for WPMU if installed: http://ocaoimh.ie/2008/07/19/sitewide-tags-pages-for-wordpress-mu/
Author: D. Sader
Version: 1.1
Author URI: http://iblog.stjschool.org/

$featured blog inspired by http://dailytestimony.net/plugins/

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 Changes:
 1.0 - 2008-08-12
 1.1 - 2008-08-24 added $before_widget - $after_widget to EACH widget, duh. Now sidebar <ul><li> formatting matches other widgets.
*/
function ds_sitewide_output_widget_init() {
//	if(!is_site_admin()) return; // testing
  $widget_title = "Sitewide Multi Widget";	// Change this to name the widget

	function widget_ds_sitewide_output_widget($args) {
		extract($args);
 		$widget_title = "Sitewide Posts";	// Change this to name the widget, again
		$options = get_option('widget_ds_sitewide_output_widget');
		$title = !isset($options['title']) ? $widget_title : $options['title'];
		$begin_wrap = '<ul>';
		$end_wrap = '</ul>';

		// These lines generate our output.

			$featured_blogs = array($options['blog_id']); // Clone multiple panel outputs such as ...
		//	$featured_blogs = array($options['blog_id'],63); 
			if (!is_array($featured_blogs)) $featured_blogs= array($featured_blogs); // hiccup
			foreach($featured_blogs as $featured_blog) {
			switch_to_blog($featured_blog); // minimize use of switch_to blog/restore_current_blog hence several widgets in one multiwidget
				if( $options['show_posts'] == TRUE ) {
 					$tag_name_variable = $options['tagname']; // return all matches to any tags seperated by a comma
					$category_name_variable = $options['catname']; // assign the variable as current category
					$number_variable = $options['limit']; // how many?
				// http://codex.wordpress.org/Template_Tags/query_posts a zillion combos
					$query_string = array(
					'tag' => $tag_name_variable, 
					'category_name' => $category_name_variable, 
					'showposts' => $number_variable
					);
 					$query = new WP_Query($query_string);
 				if ($query->have_posts()) : 
 					echo $before_widget;
 					echo $before_title . $title . $after_title;
					echo $begin_wrap; 
  					while ($query->have_posts()) : $query->the_post();
					echo '<li><p class="date">'; 
					  // whatever you can do to a loop, do it here
					  
					 if( $options['show_date'] == TRUE ) {
					    $date = the_time('F jS, Y');
						echo $date . "</p>";
						 }
					  
					if( $options['show_avatar'] == TRUE ) { 
						$avatar_size =  $options['avatar_size']; ?>
						<div style="margin-top:2px;"><?php echo get_avatar( get_the_author_id(), $avatar_size ); ?></div>
						<?php } 
					if( $options['show_title'] == TRUE ) { ?>
						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php if ( get_the_title() ) the_title(); else the_ID(); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
					<?php
						 } 
					
					if( $options['show_author'] == TRUE ) {
						echo ' posted by ';
						the_author_link(); } 
					if( $options['show_content'] == 'excerpt' ) { 
						the_excerpt();
					} elseif( $options['show_content'] == 'full' ) {
						the_content(); } 
					if( $options['show_tags'] == TRUE ) { 
						global $wp_query;
						$wp_query->in_the_loop = true;
						if (is_callable('the_tags')) the_tags('Tags: ', ', ', '<br />');
						}
					if( $options['show_category'] == TRUE ) { ?>
						<br />Posted in <?php the_category(', '); } ?> <p class="comments"> 
					<?php if( $options['show_comments_link'] == TRUE ) {
						 echo comments_popup_link(' No Comments &#187;', ' 1 Comment &#187;', ' % Comments &#187;') . '</p>'; }
					echo '</li>';
					endwhile;	
					echo $end_wrap;
					echo $after_widget;

				endif; 
				} //  end show_posts
				if( $options['tag_cloud'] == TRUE ) {
					$tc_title = $options['tc_title'];
					echo $before_widget;
					echo $before_title . $tc_title . $after_title;
					echo $begin_wrap;
					if(function_exists('wp_cumulus_createflashcode')) {
						echo wp_cumulus_createflashcode(true);
					} else {
						wp_tag_cloud(); } // default options http://codex.wordpress.org/Template_Tags/wp_tag_cloud
					echo $end_wrap;
					echo $after_widget;
				}
/*				if( $options['related'] == TRUE && is_single() ) {
					$rel_title = $options['rel_title'];
					echo $begin_wrap;
					echo $before_title . $rel_title . $after_title;
					
		?>Sitewide Related Posts Widget needed here.
    <?php 
 					echo $end_wrap;
				} */
				if( $options['archives'] == TRUE ) {
					$arc_title = $options['arc_title'];
					echo $before_widget;
					echo $before_title . $arc_title . $after_title;
					echo $begin_wrap;
						if( $options['month_archives'] == TRUE ) {	?>
							<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=1"); ?> </select>
				<?php }	/* if( $options['week_archives'] == TRUE ) {	?>
							<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Week')); ?></option> <?php wp_get_archives("type=weekly&format=option&show_post_count=1"); ?> </select>
				<?php }	*/ if( $options['day_archives'] == TRUE ) {	?>
							<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Day')); ?></option> <?php wp_get_archives("type=daily&format=option&show_post_count=1"); ?> </select>
				<?php }	if( $options['year_archives'] == TRUE ) {	?>
							<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Year')); ?></option> <?php wp_get_archives("type=yearly&format=option&show_post_count=1"); ?> </select>
					<?php }
					echo $end_wrap;
					echo $after_widget;

					}
			restore_current_blog();
			} // end foreach
	} // end output function

	function widget_ds_sitewide_output_widget_control() {
		global $wpdb;
		$options = get_option('widget_ds_sitewide_output_widget');
					$tags_blog = get_site_option( 'tags_blog_id' );

		if ( !is_array($options) )
			$options = array('title'=>$widget_title,
			 'limit'=>'10',
			 'blog_id'=>$tags_blog, 
			 'tagname'=>'',
			 'tc_title'=>'Sitewide Tag Cloud',
			 'tag_cloud'=>TRUE,
			 'arc_title'=>'Sitewide Archives',
			 'archives'=>TRUE,
			 'rel_title'=>'Sitewide Related Posts', // TODO
			 'related'=>TRUE, // TODO
			 'year_archives'=>TRUE,
			 'month_archives'=>TRUE,
			 'week_archives'=>TRUE,
			 'day_archives'=>TRUE,
			 'show_posts'=>TRUE,
			 'show_author'=>TRUE,
			 'show_date'=>TRUE,
			 'show_title'=>TRUE,
			 'show_avatar'=>TRUE,
 			 'avatar_size'=>'16',
 			 'show_content'=>'none',
 			 'show_comments_link'=>TRUE,
 			 'show_category'=>TRUE,
 			 'show_tags'=>TRUE,
			  'catname'=>'');
		if ( $_POST['ds_sitewide_output_widget-submit'] ) {
			$options['title'] = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-title']));
			$options['catname'] = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-catname']));
			$options['tagname'] = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-tagname']));
			$options['tc_title'] = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-tc_title']));
			$options['tag_cloud'] = $_POST['ds_sitewide_output_widget-tag_cloud'];
			$options['arc_title'] = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-arc_title']));
			$options['archives'] = $_POST['ds_sitewide_output_widget-archives'];
			$options['rel_title'] = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-rel_title']));
			$options['related'] = $_POST['ds_sitewide_output_widget-related'];
			$options['year_archives'] = $_POST['ds_sitewide_output_widget-year_archives'];
			$options['month_archives'] = $_POST['ds_sitewide_output_widget-month_archives'];
			$options['week_archives'] = $_POST['ds_sitewide_output_widget-week_archives'];
			$options['day_archives'] = $_POST['ds_sitewide_output_widget-day_archives'];
			$options['show_posts'] = $_POST['ds_sitewide_output_widget-show_posts'];
			$options['show_avatar'] = $_POST['ds_sitewide_output_widget-show_avatar'];
			$options['avatar_size'] = $_POST['ds_sitewide_output_widget-avatar_size'];
			if ( $options['avatar_size'] >= 80 ) $options['avatar_size'] = 80;
			if ( $options['avatar_size'] <= 16 ) $options['avatar_size'] = 16;
			$options['show_author'] = $_POST['ds_sitewide_output_widget-show_author'];
			$options['show_date'] = $_POST['ds_sitewide_output_widget-show_date'];
			$options['show_title'] = $_POST['ds_sitewide_output_widget-show_title'];
			$options['show_content'] = $_POST['ds_sitewide_output_widget-show_content'];
			$options['show_comments_link'] = $_POST['ds_sitewide_output_widget-show_comments_link'];
			$options['show_category'] = $_POST['ds_sitewide_output_widget-show_category'];
			$options['show_tags'] = $_POST['ds_sitewide_output_widget-show_tags'];
			$options['limit'] = (int) $_POST["ds_sitewide_output_widget-number"];
			if ( $options['limit'] >= 10 ) $options['limit'] = 10;
			if ( $options['limit'] <= 0 ) $options['limit'] = 1;
			
			$new_id_post = (int) $_POST["ds_sitewide_output_widget-blog_id"];

		//	$new_name_post = strip_tags(stripslashes($_POST['ds_sitewide_output_widget-blogname']));
		//	$new_id_post = get_id_from_blogname($new_name_post); // future support for blogname or blog_id but to echo the blogname(blogname.domain.org) from an id isn't as easy
		
			// validate rather than saving a bad ID
			$wpdb->hide_errors();
			$found_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id = '$new_id_post' AND public='1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'" ); // blogname?
			if($found_id)
			{	$options['blog_id'] = (int) $_POST["ds_sitewide_output_widget-blog_id"];
			} else {	
			$options['blog_id'] = get_site_option( 'tags_blog_id' );
			}
			$wpdb->show_errors();

			update_option('widget_ds_sitewide_output_widget', $options);
		}
		// Be sure you format your options to be valid HTML attributes.
		if (!isset($options['title'])) {
		$title = 'Sitewide Recent Posts'; } else {
		$title = htmlspecialchars($options['title'], ENT_QUOTES); }
		if ( !$number = (int) $options['limit'] )
		$number = 10;
		if ( !$avatar_size = (int) $options['avatar_size'] )
		$avatar_size = 16;
		if ( !$blog_id = (int) $options['blog_id'] )
		$blog_id = $tags_blog; // hopefully the tags_blog_id is there
		// http://boren.nu/archives/2007/10/01/taxonomy-intersections-and-unions/
		$catname = htmlspecialchars($options['catname'], ENT_QUOTES);
		$tagname = htmlspecialchars($options['tagname'], ENT_QUOTES);
		if (!isset($options['tc_title'])) {
		$tc_title = 'Sitewide Tag Cloud'; } else {
		$tc_title = htmlspecialchars($options['tc_title'], ENT_QUOTES); }
		$tag_cloud = $options['tag_cloud'];
		if (!isset($options['rel_title'])) {
		$rel_title = 'Sitewide Related Posts'; } else {
		$rel_title = htmlspecialchars($options['rel_title'], ENT_QUOTES); }
		$related = $options['related'];
		if (!isset($options['arc_title'])) {
		$arc_title = 'Sitewide Archives'; } else {
		$arc_title = htmlspecialchars($options['arc_title'], ENT_QUOTES); }
		$archives = $options['archives'];
		$year_archives = $options['year_archives'];
		$month_archives = $options['month_archives'];
		$week_archives = $options['week_archives'];
		$day_archives = $options['day_archives'];
		$show_posts = $options['show_posts'];
		$show_avatar = $options['show_avatar'];
		$avatar_size = $options['avatar_size'];
		$show_author = $options['show_author'];
		$show_date = $options['show_date'];
		$show_title = $options['show_title'];
		if (!isset($options['show_content'])) {
		$show_content = 'none';	} else {
		$show_content = $options['show_content']; }
		$show_comments_link = $options['show_comments_link'];
		$show_category = $options['show_category'];
		$show_tags = $options['show_tags'];
		if (function_exists('sitewide_tags_options')) { // http://ocaoimh.ie/2008/07/19/sitewide-tags-pages-for-wordpress-mu/
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-blog_id">' . __('Blog ID:') . ' <input   style="width: 25%;" id="ds_sitewide_output_widget-blog_id" name="ds_sitewide_output_widget-blog_id" type="text" value="'.$blog_id.'" /></label></p>';	
		echo '<p style="text-align:right;"><small>Tags Blog ID: <a href="'.get_blogaddress_by_id($tags_blog).'">'.$tags_blog.'</a></small></p>';
		} else {	
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-blog_id">' . __('Blog ID:') . ' <input style="width: 25%;" id="ds_sitewide_output_widget-blog_id" name="ds_sitewide_output_widget-blog_id" type="text" value="'.$blog_id.'" /></label></p>'; 
		}
		
/*		if (function_exists('sitewide_tags_options')) { // http://ocaoimh.ie/2008/07/19/sitewide-tags-pages-for-wordpress-mu/
			$tags_blogname = get_site_option( 'tags_blog' );
	// TODO		$blogname = $blog_id; // needs a simpler vhost(non) get_path(blogname)_from_id() akin to get_id_from_blogname()
						
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-blogname">' . __('Blogname:') . ' <input   style="width: 25%;" id="ds_sitewide_output_widget-blogname" name="ds_sitewide_output_widget-blogname" type="text" value="'.$blogname.'" /></label></p>';		
		echo '<p style="text-align:right;"><small>Tags Blog: <a href="'.get_blogaddress_by_id($tags_blog).'">'.$tags_blogname.'</a></small></p>';
		} else {	
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-blogname">' . __('Blogname:') . ' <input style="width: 25%;" id="ds_sitewide_output_widget-blogname" name="ds_sitewide_output_widget-blogname" type="text" value="'.$blogname.'" /></label></p>'; 
		}
*/		

		echo '<hr /><b>Sitewide Post(s)</b>';
		$checked = ( $show_posts == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_posts">' . __('Include Sitewide Posts Widget:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_posts" name="ds_sitewide_output_widget-show_posts" '.$checked.' value="TRUE" /></label><br /></p>';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-title">' . __('Title:') . ' <input style="width: 200px;" id="ds_sitewide_output_widget-title" name="ds_sitewide_output_widget-title" type="text" value="'.$title.'" /></label></p>';			
// TODO onclick show/hide
		echo '<div id="ds_sitewide_output_widget-tag_cloud">';
			$checked = ( $show_title == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_title">' . __('Show Post Title:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_title" name="ds_sitewide_output_widget-show_title" '.$checked.' value="TRUE" /></label><br /></p>';			
			$checked = ( $show_date == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_date">' . __('Show Post Date:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_date" name="ds_sitewide_output_widget-show_date" '.$checked.' value="TRUE" /></label><br /></p>';
		$checked = ( $show_author == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_author">' . __('Show Post Author:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_author" name="ds_sitewide_output_widget-show_author" '.$checked.' value="TRUE" /></label><br /></p>';
			$checked = ( $show_avatar == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_avatar">' . __('Show Author Avatar:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_avatar" name="ds_sitewide_output_widget-show_avatar" '.$checked.' value="TRUE" /></label><br /></p>';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-avatar_size">' . __('Avatar Size:') . ' <input style="width: 25%;" id="ds_sitewide_output_widget-avatar_size" name="ds_sitewide_output_widget-avatar_size" type="text" value="'.$avatar_size.'" /></label><br /><small>16=small, 32=default, 64=large, 80=XL</small></p>';
			$checked = ( $show_content == 'excerpt' ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_excerpt">' . __('Show Post Excerpt:') . ' <input type="radio" id="ds_sitewide_output_widget-show_excerpt" name="ds_sitewide_output_widget-show_content" '.$checked.' value="excerpt" /></label><br /></p>';
			$checked = ( $show_content == 'full' ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_content">' . __('Show Full Post:') . ' <input type="radio" id="ds_sitewide_output_widget-show_content" name="ds_sitewide_output_widget-show_content" '.$checked.' value="full" /></label><br /></p>';			
			$checked = ( $show_content == 'none' ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_none">' . __('Show No Content:') . ' <input type="radio" id="ds_sitewide_output_widget-show_none" name="ds_sitewide_output_widget-show_content" '.$checked.' value="none" /></label><br /></p>';			
			$checked = ( $show_comments_link == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_comments_link">' . __('Show Comments Link:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_comments_link" name="ds_sitewide_output_widget-show_comments_link" '.$checked.' value="TRUE" /></label><br /></p>';
			$checked = ( $show_category == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_category">' . __('Show Post Category:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_category" name="ds_sitewide_output_widget-show_category" '.$checked.' value="TRUE" /></label><br /></p>';
			$checked = ( $show_tags == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-show_tags">' . __('Show Post Tags:') . ' <input type="checkbox" id="ds_sitewide_output_widget-show_tags" name="ds_sitewide_output_widget-show_tags" '.$checked.' value="TRUE" /></label><br /></p>';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-number">' . __('Number of Posts:') . ' <input style="width: 25%;" id="ds_sitewide_output_widget-number" name="ds_sitewide_output_widget-number" type="text" value="'.$number.'" /></label><br /><small>1-10</small></p>';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-catname">' . __('Sitewide Category Name:') . ' <input style="width: 50%;" id="ds_sitewide_output_widget-catname" name="ds_sitewide_output_widget-catname" type="text" value="'.$catname.'" /></label><br /><small>(blank returns all posts)</small></p>';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-tagname">' . __('Sitewide Tag Name:') . ' <input style="width: 50%;" id="ds_sitewide_output_widget-tagname" name="ds_sitewide_output_widget-tagname" type="text" value="'.$tagname.'" /></label><br /><small>(comma separated list)</small></p>';
echo '</div>';

		echo '<hr />';
		echo '<b>Sitewide Tag Cloud</b>';
			$checked = ( $tag_cloud == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-tag_cloud">' . __('Include Sitewide Tag Cloud Widget:') . ' <input type="checkbox" id="ds_sitewide_output_widget-tag_cloud" name="ds_sitewide_output_widget-tag_cloud" '.$checked.' value="TRUE" /></label><br /></p>';
// TODO onclick show/hide
		echo '<div id="ds_sitewide_output_widget-tag_cloud">';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-tc_title">' . __('Tag Cloud Title:') . ' <input style="width: 60%;" id="ds_sitewide_output_widget-tc_title" name="ds_sitewide_output_widget-tc_title" type="text" value="'.$tc_title.'" /></label></p>';
		echo '</div>';
		echo '<hr />';
		echo '<b>Sitewide Archives</b>';
			$checked = ( $archives == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-archives">' . __('Include Sitewide Archives Widget:') . ' <input type="checkbox" id="ds_sitewide_output_widget-archives" name="ds_sitewide_output_widget-archives" '.$checked.' value="TRUE" /></label><br /></p>';
// TODO onclick show/hide
		echo '<div id="ds_sitewide_output_widget-archives">';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-arc_title">' . __('Archives Title:') . ' <input style="width: 60%;" id="ds_sitewide_output_widget-arc_title" name="ds_sitewide_output_widget-arc_title" type="text" value="'.$arc_title.'" /></label></p>';
			$checked = ( $year_archives == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-year_archives">' . __('Yearly Archives:') . ' <input type="checkbox" id="ds_sitewide_output_widget-year_archives" name="ds_sitewide_output_widget-year_archives" '.$checked.' value="TRUE" /></label><br /></p>';
			$checked = ( $month_archives == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-month_archives">' . __('Monthly Archives:') . ' <input type="checkbox" id="ds_sitewide_output_widget-month_archives" name="ds_sitewide_output_widget-month_archives" '.$checked.' value="TRUE" /></label><br /></p>';
		/* TODO: weekly archives needs more testing as this borked in my tests, but I don't know why
			$checked = ( $week_archives == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-week_archives">' . __('Weekly Archives:') . ' <input type="checkbox" id="ds_sitewide_output_widget-week_archives" name="ds_sitewide_output_widget-week_archives" '.$checked.' value="TRUE" /></label><br /></p>'; */
			$checked = ( $day_archives == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-day_archives">' . __('Daily Archives:') . ' <input type="checkbox" id="ds_sitewide_output_widget-day_archives" name="ds_sitewide_output_widget-day_archives" '.$checked.' value="TRUE" /></label><br /></p>';
		echo '</div>';

/*		echo '<hr />';
		echo '<b>Sitewide Related Posts</b>';
			$checked = ( $related == TRUE ) ? ' checked="checked"' : '';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-related">' . __('Include Sitewide Related Posts:') . ' <input type="checkbox" id="ds_sitewide_output_widget-related" name="ds_sitewide_output_widget-related" '.$checked.' value="TRUE" /></label><br /></p>';
		echo '<div id="ds_sitewide_output_widget-related">';
		echo '<p style="text-align:right;"><label for="ds_sitewide_output_widget-rel_title">' . __('Related Posts Title:') . ' <input style="width: 60%;" id="ds_sitewide_output_widget-rel_title" name="ds_sitewide_output_widget-rel_title" type="text" value="'.$rel_title.'" /></label></p>';
		echo '</div>';

*/
		echo '<input type="hidden" id="ds_sitewide_output_widget-submit" name="ds_sitewide_output_widget-submit" value=" " />';
	} // end control function
	$widget_ops = array('classname' => 'widget_ds_sitewide_output_widget', 'description' => __( "$widget_title") );
	$control_ops = array('width' => 320);

	wp_register_sidebar_widget('ds_sitewide_output_widget', $widget_title, 'widget_ds_sitewide_output_widget', $widget_ops);
	wp_register_widget_control('ds_sitewide_output_widget', $widget_title, 'widget_ds_sitewide_output_widget_control', $control_ops );
} // end init
add_action('widgets_init', 'ds_sitewide_output_widget_init');
?>